import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
    username: ''
}
const mutations = {
    setUsername: (state, username) => {
        state.username = username

        // 1.将用户名存储到本地
        localStorage.setItem('uname', username)
    }
}
const actions = {}
const getters = {
    username: state => {
        // 2.用vuex中的计算属性获取到本地存储到的用户名
        return localStorage.getItem('uname')
    }
}

export default new Vuex.Store({
    state,
    getters,
    actions,
    mutations
})